from PIL import ImageFont


# 对文本的换行，在文本区域里面的长度有限，需要换行，在字符串里面插入换行符
def auto_next_line(s: str, font: ImageFont, length: int) -> str:
    pointer = 0
    temp = ""
    for i in range(len(s)):
        if font.getlength(s[pointer:i + 1]) > length:
            temp += "\n" + s[i]
            pointer = i + 1
        else:
            temp += s[i]
    return temp
